package com.bjt.wms.sys.service;

import com.bjt.common.config.paragetter.BasePageRequest;
import com.bjt.wms.sys.model.Employee;
import com.bjt.wms.sys.model.Permission;
import com.bjt.utils.R;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;

import java.util.List;

public class EmployeeService {

    public R queryEmployeeList(BasePageRequest<Employee> basePageRequest, Kv cond) {
        SqlPara sqlPara = Db.getSqlPara("sys.employee.queryList", Kv.by("cond", cond));

        Page<Record> pageData = Db.paginate(basePageRequest.getPage(), basePageRequest.getLimit(), sqlPara);
        return R.ok().put("data", pageData.getList()).put("count", pageData.getTotalRow());
    }

    /**
     * 查询所有人员信息
     */
    public List<Employee> list() {
        return Employee.dao.find("select * from employee");
    }

    /**
     * 根据人员ID查询权限信息
     */
    public Permission getEmployeePermission(int employeeId) {
        return Permission.dao.findFirst("select p.* from permission p where p.employee_id=?", employeeId);
    }
}
